<?php

use yii\helpers\Url;

?>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2><?=getSet(1)?></h2>
            <p><?=getSet(1)?>后台管理系统</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="LAY-user-login-username"></label>
                <input type="text" name="name" id="LAY-user-login-username" lay-verify="required" placeholder="用户名"
                       class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="required"
                       placeholder="密码" class="layui-input">
                <input type="hidden" name="<?=Yii::$app->request->csrfParam?>" value="<?=Yii::$app->request->csrfToken?>">
            </div>
            <div class="layui-form-item" style="margin-bottom: 20px;">
                <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">

            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" id="login" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
            </div>
        </div>
    </div>

    <div class="layui-trans layadmin-user-login-footer">

        <p>© 2018 <a href="http://www.layui.com/" target="_blank">layui.com</a></p>
        <p>
            <span><a href="http://www.layui.com/admin/#get" target="_blank">获取授权</a></span>
            <span><a href="http://www.layui.com/admin/pro/" target="_blank">在线演示</a></span>
            <span><a href="http://www.layui.com/admin/" target="_blank">前往官网</a></span>
        </p>
    </div>
</div>
<?php $this->beginBlock('footer') ?>
<script>
    layui.config({
        base: '<?=Url::base()?>/resources/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'user'], function () {
        var $ = layui.$
            , form = layui.form;
        form.render();
        //提交
        form.on('submit(LAY-user-login-submit)', function (obj) {
            //请求登入接口
            console.log(obj.field);
            $.post('<?=Url::toRoute(['site/login'])?>',obj.field,function (res) {
               if(res.status==200){
                    layer.msg(res.msg,{icon:1,time:1000},function () {
                        location.href = '<?= Url::to(['/']) ?>';
                    })
               }else {
                   layer.msg(res.msg,{offset:'15px',icon: 2})
               }
            },'json');
        });
    });
    $(function () {
        document.onkeydown = function (event) {
            var e = event || window.event ||arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 13) {
                $('#login').click();
            }
        };
    });
</script>
<?php $this->endBlock() ?>
